package com.gourd.common.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.util.StringUtils;

/**
 * html工具类
 * Created on 2017/11/26.
 *
 * @author gourd
 */
public class HtmlImgUtil {

     /**
     *  去除图片
     * @param richContent html格式富文本信息
     * @return
     */
    public static String  handleImage(String richContent){
        if(StringUtils.isEmpty(richContent)){
            return richContent;
        }
        Document doc = Jsoup.parseBodyFragment(richContent, "utf-8");
        Elements imgList = doc.getElementsByTag("img");
        for(Element img :imgList){
            //将有效的路径传入null
            img.attr("src", "");
        }
        return  doc.getElementsByTag("body").html();
    }


}
